//
//  ZPOnlineServeVC.m
//  ZhenPin
//
//  Created by fei on 14-7-11.
//  Copyright (c) 2014年 zhenpin. All rights reserved.
//

#import "ZPOnlineServeVC.h"

@interface ZPOnlineServeVC ()

@end

@implementation ZPOnlineServeVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
        self.title = @"在线客服";
    
    serveWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-64)];
    
    
    NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/ServerConfig.plist"];
    NSMutableDictionary *dataDic = [[NSDictionary dictionaryWithContentsOfFile:homePath] mutableCopy];
    NSString *urlString = dataDic[@"zpSever"];
    [serveWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
    serveWebView.scalesPageToFit = NO;
    
    [self.view addSubview:serveWebView];
    
    requestHud = [[MBProgressHUD alloc] initWithView:self.view];
    [requestHud setMode:MBProgressHUDModeIndeterminate];
    [requestHud show:YES];
    [requestHud setHidden:NO];
    serveWebView.delegate = self;
    [self.view addSubview:requestHud];
    
    [self setNavBackButtonItem];
    
    
}

#pragma mark -- UIWebView Delegate 
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    [requestHud setHidden:YES];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
    [requestHud setHidden:YES];
}
-(void)webViewDidStartLoad:(UIWebView *)webView {
    [requestHud setHidden:NO];
}

-(void)setNavBackButtonItem {

    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 20);
    [backBtn setImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(leftBarbuttonItemClicked:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = leftBarItem;
}

-(void)leftBarbuttonItemClicked:(UIButton *)button {
    [self fadeOut];
}


-(void)navigationBackClicked {
    [self fadeOut];
}

-(void)fadeOut {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
